forgottenrealmsfandomcom_pt_br-20200215-history
Predefinição:Imagem em destaque/doc/underthehood
Under the hood What follows is a detailed, line by line explanation of how this template works, for those who really want to know. This template uses DynamicPageList (DPL) which is fully documented here. Below is the essential part of the template: 1. }}} 4. | include = {Formato imagem em destaque} 5. | includematch = /\s*usethis\s*=\s*(all¦ )/si 6. | noresultsheader = }}} }} 7. | allowcachedresults = false 8. | eliminate = categories,images }} #The first line declares we are using DPL in parser function mode (like ), then } is replaced by 22 abril. If called without an argument, } is undefined and the default value is substituted instead. Using 22 abril for example, the full title of the page we are searching for would be "Predefinição:Imagem em destaque/22 abril". #*The default value is the concatenation of the two Magic Words and separated by a space. The last time this page (the one you are reading right now) was cached, the default value was GMT. #Assuming the page was found, this tells what part of the page to fetch and present as the output of this template. We want all templates, rendered just as if they were on the page in place of . #*If the page we found did not contain a template, then DPL would give up at this point and call and return those results, whatever they might be. #If we find one or more templates on the page, then they have to match certain criteria, given by this regular expression, or they will be skipped. In English, the regular expression is looking for possible whitespace, then the word "usethis", followed by maybe more whitespace, an equals sign, yet more optional whitespace, then either the word "all" or the value of the AM/PM field in the current timestamp. If a match is found, then the template is sent to the output and we move on to the next one, if any. Here's a slightly more technical description of the regular expression: #*The regexp starts and ends with a forward slash, " / ". The "s" at the end specifies that the parser should consider newline characters as whitespace (which means, for example, that "usethis" and "=" don't have to be on the same line in the "22 abril" file. The "i" at the end specifies that all string comparisons should ignore case (which means you can write "useThis = PM" if you want). #*"\s" is shorthand for "whitespace" and the " * " means "zero or more of these". So "\s*" matches any amount of whitespace (including newlines because of the trailing "s") or no spaces at all (so you can write "usethis=AM" if you want). #*Next it tries to match the string "usethis" (ignoring case due to the trailing "i"). #*Match "\s*" for zero or more whitespace. #*Match an equals sign " = " #*Match "\s*" for zero or more whitespace. #*The left parenthesis, " ( " starts a subpattern. We can match any of the things inside the parentheses. They are separated by the broken pipe symbol, " ¦ " which performs a logical OR function. Normally, regular expressions use the pipe symbol, " | " here, but since templates use the pipe to separate parameters, it would confuse the parser, so we use the broken pipe instead. #*The first optional subpattern match is the word "all". #*The second optional subpattern is the current AM/PM indicator as given by . So whenever the template is called, will be replaced by either "am" or "pm" depending on whether it is before noon or after noon, GMT. The last time this doc page was cached, it was . #*The right parenthesis closes off the subpattern. #*The last forward slash closes off the regexp, leaving the "si" which we discussed earlier. We're done! #This line tells DPL what to do if the file matching the title does not exist—we call with either the value of the parameter } ("22 abril" in our example), or the current day month pair, if we didn't specify a date. The .default template will compute the nearest day that is a multiple of 7, plus 1, and try again. Right now, it computes | |0}} / 7) round 0) * 7) + 1}}. #This tells DPL to ignore any cached results (which might be stale by a few hours) and return fresh results. #And finally, this command tells DPL to remove any categories from the included code and remove references to any images before sending the output to the page that called this template. Otherwise, the calling page would be put in whatever categories had been assigned to the , and the "What links here" report for any images included would show that the calling page linked them, which is not true. Category:Documentação de predefinição